﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace VikingArcade_v2._0
{
    public class DisplayController
    {
        public delegate void OnToggleFullScreen(Size oldSize, Size newSize);

        public static event OnToggleFullScreen FullScreenToggled;

        public Display Display { get; set; }

        public static Camera Camera { get; set; }

        public static GraphicsDevice GraphicsDevice
        {
            get
            {
                return graphicsDeviceManager.GraphicsDevice;
            }
        }

        private static GraphicsDeviceManager graphicsDeviceManager;

        private static Size windowedSize;

        public static Size FullScreenResolution { get; set; }

        public DisplayController(GraphicsDeviceManager graphicsDeviceManager)
        {
            Camera = new Camera();
            Display = new Display();
            DisplayController.graphicsDeviceManager = graphicsDeviceManager;
            windowedSize = new Size(GraphicsDevice.PresentationParameters.BackBufferWidth,
                                    GraphicsDevice.PresentationParameters.BackBufferHeight);
            FullScreenResolution = SystemInformation.PrimaryMonitorMaximizedWindowSize;
        }

        public static void ToggleFullScreen()
        {
            if(graphicsDeviceManager.IsFullScreen)
            {
                graphicsDeviceManager.PreferredBackBufferHeight = windowedSize.Height;
                graphicsDeviceManager.PreferredBackBufferWidth = windowedSize.Width;
            }
            else
            {
                windowedSize = new Size(GraphicsDevice.PresentationParameters.BackBufferWidth,
                                    GraphicsDevice.PresentationParameters.BackBufferHeight);
                graphicsDeviceManager.PreferredBackBufferHeight = FullScreenResolution.Height;
                graphicsDeviceManager.PreferredBackBufferWidth = FullScreenResolution.Width;
            }
            Size oldSize = new Size(GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);
            graphicsDeviceManager.ToggleFullScreen();
            Size newSize = new Size(GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);
            FullScreenToggled.Invoke(oldSize, newSize);
        }
    }
}
